package com.example.qianfeng.image.stream;

import java.io.File;
import java.util.Calendar;
import java.util.Date;

/**
 * 判断字符流是否为图片
 */
public class JudgeStream {
    private final static File IMG_PATH = new File("D:\\pictures\\statics\\img");

    public static void main(String[] args) {
        /*
        FileUploadUtil uploadUtil = new FileUploadUtil();
        // 获取所有目录及文件
        File[] files = IMG_PATH.listFiles();
        String targetPath = "/home/images";
        String remoteFileName;
        for (int i = 0; i < files.length; i++) {
            try {
                remoteFileName = System.currentTimeMillis() + ".jpg";
                uploadUtil.uploadFile(files[i], targetPath, remoteFileName);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
         */

        // 判断时间是否过期
        String dateTime = "20221231102013";
        long timeStampSys = ImageFormatChecker.getTimeStampSys(dateTime);
        Date date = new Date(Long.parseLong(String.valueOf(timeStampSys)));
        Calendar calendar = Calendar.getInstance();
        Date nowTime = calendar.getTime();
        calendar.setTime(date);
        // 图片上传保存一个月检查
        calendar = ImageFormatChecker.initCalendar(calendar);
        Date outTime = calendar.getTime();
        if (nowTime.after(outTime)) {
            System.out.println("已经过期");
        }
    }
}
